[Deepin-Kernel-SIG] [linux 6.6-y] [Upstream] x86/selftests: Skip the tests if prerequisites aren't fulfilled#835
Conversation
commit 99c8431 upstream. Skip instead of failing when prerequisite conditions aren't fulfilled, such as invalid xstate values etc. Make the tests show as 'SKIP' when run: make -C tools/testing/selftests/ TARGETS=x86 run_tests ... # timeout set to 45 # selftests: x86: amx_64 # # xstate cpuid: invalid tile data size/offset: 0/0 ok 42 selftests: x86: amx_64 # SKIP # timeout set to 45 # selftests: x86: lam_64 # # Unsupported LAM feature! ok 43 selftests: x86: lam_64 # SKIP ... In the AMX test, Move away from check_cpuid_xsave() and start using arch_prctl() to find out if AMX support is present or not. In the kernels where AMX isn't present, arch_prctl() returns -EINVAL, hence it is backward compatible. Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Reviewed-by: Chang S. Bae <chang.seok.bae@intel.com> Reviewed-by: Binbin Wu <binbin.wu@linux.intel.com> Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Link: https://lore.kernel.org/r/20240327111720.3509180-1-usama.anjum@collabora.com [ Zelin Deng: ANBZ: #8853 ] Link: https://gitee.com/anolis/cloud-kernel/pulls/3125 Signed-off-by: Zelin Deng <zelin.deng@linux.alibaba.com> [ WangYuli: Edit commit msg. ] [ Backport from v6.9 ] Signed-off-by: WangYuli <wangyuli@uniontech.com>
Reviewer's GuideUpdates x86 selftests to skip rather than fail when prerequisites aren’t met: AMX tests now use arch_prctl for feature detection and return KSFT_SKIP if AMX is unavailable; LAM tests similarly return KSFT_SKIP when unsupported. Sequence Diagram for AMX Test Feature Detection LogicsequenceDiagram
participant TestRunner
participant AMXTest as "amx.c main()"
participant Kernel
TestRunner->>AMXTest: Execute test
AMXTest->>Kernel: syscall(SYS_arch_prctl, ARCH_GET_XCOMP_SUPP, &features)
Kernel-->>AMXTest: rc, features
alt AMX not supported (rc != 0 or features & XFEATURE_MASK_XTILE != XFEATURE_MASK_XTILE)
AMXTest->>AMXTest: ksft_print_msg("no AMX support")
AMXTest-->>TestRunner: Return KSFT_SKIP
else AMX supported
AMXTest->>AMXTest: check_cpuid_xtiledata()
AMXTest->>AMXTest: Proceed with AMX tests
AMXTest-->>TestRunner: Return test result (e.g. KSFT_PASS)
end
Sequence Diagram for LAM Test Prerequisite Check and Skip LogicsequenceDiagram
participant TestRunner
participant LAMTest as "lam.c main()"
TestRunner->>LAMTest: Execute test
LAMTest->>LAMTest: Check if cpu_has_lam()
alt LAM not supported
LAMTest->>LAMTest: ksft_print_msg("Unsupported LAM feature!")
LAMTest-->>TestRunner: Return KSFT_SKIP
else LAM supported
LAMTest->>LAMTest: Proceed with LAM tests
LAMTest-->>TestRunner: Return test result (e.g. KSFT_PASS)
end
Class Diagram of Modified x86 Selftest Files and Key FunctionsclassDiagram
class `tools/testing/selftests/x86/amx.c` {
+main() int
}
class `tools/testing/selftests/x86/lam.c` {
+main(argc: int, argv: char**) int
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
deepin pr auto review代码审查意见:
总体来说,这些改动提高了代码的可读性和可维护性,但需要确保所有新增的宏和函数都在正确的位置定义,并且与现有的代码库兼容。 |
There was a problem hiding this comment.
Pull Request Overview
This pull request updates the selftests for x86 by modifying the behavior when prerequisite conditions are not met, so tests now show as SKIP rather than failing.
- In lam.c, the test now returns KSFT_SKIP instead of -1 for unsupported LAM.
- In amx.c, the legacy check_cpuid_xsave function is removed and replaced with an arch_prctl() call to detect AMX support.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tools/testing/selftests/x86/lam.c | Replaces a failing return value with KSFT_SKIP for unsupported LAM. |
| tools/testing/selftests/x86/amx.c | Removes the cpuid-based check and adds an arch_prctl based check for AMX support. |
Comments suppressed due to low confidence (2)
tools/testing/selftests/x86/lam.c:1186
- Using KSFT_SKIP clearly indicates that the test is being skipped when LAM is unsupported; please ensure that this macro is documented and consistently used across the selftests.
return KSFT_SKIP;
tools/testing/selftests/x86/amx.c:920
- Ensure that the XFEATURE_MASK_XTILE macro is defined and available in the appropriate header, since it is used to verify AMX support immediately afterward.
rc = syscall(SYS_arch_prctl, ARCH_GET_XCOMP_SUPP, &features);
| long rc; | ||
|
|
||
| rc = syscall(SYS_arch_prctl, ARCH_GET_XCOMP_SUPP, &features); | ||
| if (rc || (features & XFEATURE_MASK_XTILE) != XFEATURE_MASK_XTILE) { |
There was a problem hiding this comment.
[nitpick] Consider adding explicit parentheses around '(features & XFEATURE_MASK_XTILE)' for clarity, e.g., 'if (rc || ((features & XFEATURE_MASK_XTILE) != XFEATURE_MASK_XTILE))'.
| if (rc || (features & XFEATURE_MASK_XTILE) != XFEATURE_MASK_XTILE) { | |
| if (rc || ((features & XFEATURE_MASK_XTILE) != XFEATURE_MASK_XTILE)) { |
There was a problem hiding this comment.
Hey @Avenger-285714 - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
commit 99c8431 upstream.
Skip instead of failing when prerequisite conditions aren't fulfilled, such as invalid xstate values etc.
Make the tests show as 'SKIP' when run:
make -C tools/testing/selftests/ TARGETS=x86 run_tests
...
timeout set to 45
selftests: x86: amx_64
# xstate cpuid: invalid tile data size/offset: 0/0
ok 42 selftests: x86: amx_64 # SKIP
timeout set to 45
selftests: x86: lam_64
# Unsupported LAM feature!
ok 43 selftests: x86: lam_64 # SKIP
...
In the AMX test, Move away from check_cpuid_xsave() and start using arch_prctl() to find out if AMX support is present or not. In the kernels where AMX isn't present, arch_prctl() returns -EINVAL, hence it is backward compatible.
Reviewed-by: Chang S. Bae chang.seok.bae@intel.com
Reviewed-by: Binbin Wu binbin.wu@linux.intel.com
Acked-by: Kirill A. Shutemov kirill.shutemov@linux.intel.com
Link: https://lore.kernel.org/r/20240327111720.3509180-1-usama.anjum@collabora.com
[ Zelin Deng: ANBZ: #8853 ]
Link: https://gitee.com/anolis/cloud-kernel/pulls/3125
[ WangYuli: Edit commit msg. ]
[ Backport from v6.9 ]
Summary by Sourcery
Update x86 selftests to skip AMX and LAM tests when hardware or OS support is missing instead of failing.
Enhancements: